//trade模块的小仓库
import {reqfindUserAddressList ,reqOrderTrade ,reqsubmitOrder} from '@/api'
// actions 处理异步，接受服务器端的数据
const actions = {
  // 取服务器用户地址
  async getUserAddressList(context,value){
    let result = await reqfindUserAddressList()
    if(result.code==200){
      context.commit('GETUSERADDRESSLIST',result.data)
    }else{
      return Promise.reject(new Error('faile'))
    }
  },
  // 取服务器购物车详情
  async getTradeDetail(context,value){
    let result = await reqOrderTrade()
    if(result.code==200){
      context.commit('GETTRADEDETAIL',result.data)
    }
  }, 
  // 取服务器订单详情
  async getsubmitOrder(context,{tradeNo,data}){
    let result = await reqsubmitOrder(tradeNo,data)
    console.log(result);
  }
}
//mutations 修改state的唯一方法
const mutations = {
  GETUSERADDRESSLIST(state,addressInfo){
    state.addressInfo = addressInfo
  },
  GETTRADEDETAIL(state,ArrayInfo){
    state.ArrayInfo = ArrayInfo
  }
}
//state仓库存储数据
const state = {
  addressInfo:{},
  ArrayInfo:{}
}
// getters 计算属性，组件获取仓库的数据更加方便
const getters = {}

export default {
    state,
    actions,
    mutations,
    getters,
  };